import Vue from 'vue'
import qs from 'qs'
import { COMMON_METHOD } from '@/constant/common'
const moduleName = 'cip'

// 应用
export const apiApp = Object.assign({}, COMMON_METHOD, {
  serveUrl: '/' + moduleName + '/' + 'apiApp' + '/',
  enable(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/enable')
  },
  disable(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/disable')
  },
  // 重置密钥
  resetSecret(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/resetSecret')
  },
  // 授予接口服务权限
  grantApiPermission(id, apiServiceIdList) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/grantApiPermission', qs.stringify(apiServiceIdList, { arrayFormat: 'repeat' }))
  },
  // 收回接口服务权限
  withdrawApiPermission(id, apiServiceIdList) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/withdrawApiPermission', qs.stringify(apiServiceIdList, { arrayFormat: 'repeat' }))
  },
  // 授予消息主题权限
  grantMessageTopicPermission(id, apiMessageTopicIdList) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/grantMessageTopicPermission', qs.stringify(apiMessageTopicIdList, { arrayFormat: 'repeat' }))
  },
  // 收回消息主题权限
  withdrawMessageTopicPermission(id, apiMessageTopicIdList) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/withdrawMessageTopicPermission', qs.stringify(apiMessageTopicIdList, { arrayFormat: 'repeat' }))
  }

}
)

// 接口服务
export const apiService = Object.assign({}, COMMON_METHOD, {
  serveUrl: '/' + moduleName + '/' + 'apiService' + '/',
  enable(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/enable')
  },
  disable(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/disable')
  },
  queryApiPermission(params) {
    return Vue.prototype.$httpRequest.get(this.serveUrl + 'queryApiPermission', params)
  }

}
)

// 接口服务日志
export const apiServiceLog = Object.assign({}, COMMON_METHOD, {
  serveUrl: '/' + moduleName + '/' + 'apiServiceLog' + '/'

}
)

// 消息主题
export const apiMessageTopic = Object.assign({}, COMMON_METHOD, {
  serveUrl: '/' + moduleName + '/' + 'apiMessageTopic' + '/',
  enable(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/enable')
  },
  disable(id) {
    return Vue.prototype.$httpRequest.put(this.serveUrl + id + '/disable')
  },
  queryMessageTopicPermission(params) {
    return Vue.prototype.$httpRequest.get(this.serveUrl + 'queryMessageTopicPermission', params)
  }

}
)

// 消息服务日志
export const apiMessageLog = Object.assign({}, COMMON_METHOD, {
  serveUrl: '/' + moduleName + '/' + 'apiMessageLog' + '/'

}
)

// 数据权限
export const apiDataPermission = Object.assign({}, COMMON_METHOD, {
  serveUrl: '/' + moduleName + '/' + 'apiDataPermission' + '/'

}
)
